unit_threaded.randomized

Modules

benchmark
module unit_threaded.randomized.benchmark
gen
module unit_threaded.randomized.gen
random
module unit_threaded.randomized.random

Examples

1 import core.thread : Thread;
2 import core.time : seconds;
3 
4 struct Foo {
5     void superSlowMethod(int a, Gen!(int, -10, 10) b) {
6         Thread.sleep(1.seconds / 250000);
7         doNotOptimizeAway(a);
8     }
9 }
10 
11 Foo a;
12 
13 auto del = delegate(int ai, Gen!(int, -10, 10) b) {
14     a.superSlowMethod(ai, b);
15 };
16 
17 benchmark!(del)();
1 import std.string : indexOf;
2 import std.experimental.logger;
3 
4 class SingleLineLogger : Logger {
5     this() {
6         super(LogLevel.info);
7     }
8 
9     override void writeLogMsg(ref LogEntry payload) @safe {
10         this.line = payload.msg;
11     }
12 
13     string line;
14 }
15 
16 auto oldLogger = stdThreadLocalLog;
17 auto newLogger = new SingleLineLogger();
18 stdThreadLocalLog = newLogger;
19 scope (exit)
20     stdThreadLocalLog = oldLogger;
21 
22 static int failingFun(int a, string b) {
23     throw new Exception("Hello");
24 }
25 
26 log();
27 benchmark!failingFun();
28 
29 assert(newLogger.line.indexOf("'a'") != -1);
30 assert(newLogger.line.indexOf("'b'") != -1);

Meta